﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using DigiLib;
using System.Security.Cryptography;

public partial class controls_admin_EmailQueue : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            try
            {
                base.bindDDL(ddlCategory, BO_portal_categories.SelectByParent(18, 1), "FULL_CATEGORY_NAME", "CATEGORY_ID");
                base.bindDDL(ddlRegions, BO_portal_regions.SelectByParent(0), "REGION_NAME_VN", "REGION_ID");
                loadData();
            }
            catch (Exception ex)
            {
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message);
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            int category_id = Convert.ToInt32(ddlCategory.SelectedValue);
            int region_id = Convert.ToInt32(ddlRegions.SelectedValue);
            string title = txtFULL_ARTICLE_TITLE.Text.Trim();
            string details = ckContent.Text.Trim();
            string strResult = BO_portal_email_queue.Insert(title, details, category_id, region_id, 0, 0, false, DateTime.Now, Administrator.USER_NAME, DateTime.Now, Administrator.USER_NAME, 1);
            if (strResult != "0")
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Đăng tin thành công!");
            }
            else
                divMessage.InnerHtml = MessageBox.Error("Lỗi", "Có lỗi trong quá trình xử lý! Đăng tin thất bại!");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát sinh lỗi như sau: " + ex.Message);
        }
    }
    private void loadData()
    {
        ObjDT = BO_portal_email_queue.Search(Convert.ToInt32(ddlCategory.SelectedValue), Convert.ToInt32(ddlRegions.SelectedValue));
        if (ObjDT.Rows.Count > 0)
        {
            txtFULL_ARTICLE_TITLE.Text = ObjDT.Rows[0]["MAIL_TITLE"].ToString();
            ckContent.Text = ObjDT.Rows[0]["MAIL_CONTENT"].ToString();
        }
        else
            divMessage.InnerHtml = MessageBox.Warning("Thông báo", "Chưa có dữ liệu");
    }
    protected void reload(object sender, EventArgs e)
    {
        loadData();
    }
}
